package org.codetranslators.common;

import java.util.Vector;

public class GraphTestMain {

	public static void main(String args[]){
		GraphTestMain gtm = new GraphTestMain();
		Node startNode = new Node("A");
		DiGraph graph = gtm.createGraph(startNode);
		
		SpanningTreeDFS spanningTreeDFS = new SpanningTreeDFS();
		spanningTreeDFS.execute(graph, startNode);
		SpanningTreeNode spanningTree = (SpanningTreeNode) spanningTreeDFS.getResult();
		spanningTree.display();
		System.out.println("BACK EDGES: ");
		Vector backEdges = spanningTreeDFS.getBackEdges();
		for(int i = 0; i < backEdges.size(); i++){
			Edge edge = (Edge) backEdges.elementAt(i);
			edge.display();
		}
	}
	
	public DiGraph createGraph(Node startNode){
		DiGraph graph = new DiGraph();
		
		// Create the nodes first
		Node nodeB = new Node("B");
		Node nodeC = new Node("C");
		Node nodeD = new Node("D");
		Node nodeE = new Node("E");
		Node nodeF = new Node("F");
		Node nodeG = new Node("G");
		Node nodeH = new Node("H");
		Node nodeI = new Node("I");
		Node nodeJ = new Node("J");
		Node nodeK = new Node("K");
		Node nodeL = new Node("L");
		Node nodeM = new Node("M");
		
		// Add the nodes to the graph
		graph.addNode(startNode);
		graph.addNode(nodeB);
		graph.addNode(nodeC);
		graph.addNode(nodeD);
		graph.addNode(nodeE);
		graph.addNode(nodeF);
		graph.addNode(nodeG);
		graph.addNode(nodeH);
		graph.addNode(nodeI);
		graph.addNode(nodeJ);
		graph.addNode(nodeK);
		graph.addNode(nodeL);
		graph.addNode(nodeM);
		
		// Create the links
		Edge edgeAB = new Edge(startNode, nodeB);
		Edge edgeAC = new Edge(startNode, nodeC);
		Edge edgeBD = new Edge(nodeB, nodeD);
		Edge edgeBG = new Edge(nodeB, nodeG);
		Edge edgeDF = new Edge(nodeD, nodeF);
		Edge edgeDG = new Edge(nodeD, nodeG);
		Edge edgeFI = new Edge(nodeF, nodeI);
		Edge edgeFK = new Edge(nodeF, nodeK);
		Edge edgeIL = new Edge(nodeI, nodeL);
		Edge edgeKL = new Edge(nodeK, nodeL);
		Edge edgeGJ = new Edge(nodeG, nodeJ);
		Edge edgeJI = new Edge(nodeJ, nodeI);
		Edge edgeCE = new Edge(nodeC, nodeE);
		Edge edgeCH = new Edge(nodeC, nodeH);
		Edge edgeEC = new Edge(nodeE, nodeC);
		Edge edgeEH = new Edge(nodeE, nodeH);
		Edge edgeHM = new Edge(nodeH, nodeM);
		Edge edgeLB = new Edge(nodeL, nodeB);
		Edge edgeLM = new Edge(nodeL, nodeM);
		
		// Add the edges to the graph
		graph.addDirectedEdge(edgeAB, startNode, nodeB);
		graph.addDirectedEdge(edgeAC, startNode, nodeC);
		graph.addDirectedEdge(edgeBD, nodeB, nodeD);
		graph.addDirectedEdge(edgeBG, nodeB, nodeG);
		graph.addDirectedEdge(edgeDF, nodeD, nodeF);
		graph.addDirectedEdge(edgeDG, nodeD, nodeG);
		graph.addDirectedEdge(edgeGJ, nodeG, nodeJ);
		graph.addDirectedEdge(edgeFI, nodeF, nodeI);
		graph.addDirectedEdge(edgeFK, nodeF, nodeK);
		graph.addDirectedEdge(edgeIL, nodeI, nodeL);
		graph.addDirectedEdge(edgeKL, nodeK, nodeL);
		graph.addDirectedEdge(edgeJI, nodeJ, nodeI);
		graph.addDirectedEdge(edgeCE, nodeC, nodeE);
		graph.addDirectedEdge(edgeCH, nodeC, nodeH);
		graph.addDirectedEdge(edgeEC, nodeE, nodeC);
		graph.addDirectedEdge(edgeEH, nodeE, nodeH);
		graph.addDirectedEdge(edgeHM, nodeH, nodeM);
		graph.addDirectedEdge(edgeLB, nodeL, nodeB);
		graph.addDirectedEdge(edgeLM, nodeL, nodeM);
				
		return graph;
	}
}
